﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductTypeCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductTypeCommandHandler
{
    public class ProductTypePilDelCommandHandler : IRequestHandler<ProductTypePilDelCommand, int>
    {
        private readonly IProductTypeRepository _repository;
        public ProductTypePilDelCommandHandler(IProductTypeRepository repository)
        {
            _repository = repository;
        }
        public async Task<int> Handle(ProductTypePilDelCommand request, CancellationToken cancellationToken)
        {
            var list= (await _repository.GetAll()).Where(x=>request.ProductTypeId.Contains(x.ProductTypeId)).ToList();
            list.ForEach(x =>
            {
                x.IsDelete = true;
                x.DeleteName = "admin";
                x.DeleteTime = DateTime.Now;
            });
            return await _repository.IsUpdate(list);
        }
    }
}
